$(function () {
    $("#jqGrid").jqGrid({
        url:baseURL+"sys/reback/list" ,
        datatype: "json",
        colModel: [
            { label: '报备id', name: 'logId', width: 40,align:'center' , sortable: false},
            { label: 'SN', name: 'sn', width: 95,align:'center' , sortable: false},
            { label: '商户名称', name: 'merchantName', width: 45,align:'center', sortable: false},
            { label: '联系方式', name: 'phone', width: 75,align:'center', sortable: false},
            { label: '报备人', name: 'reportName', width: 75,align:'center', sortable: false},
            { label: '报备时间', name: 'reportDate', width: 75,align:'center', sortable: false},
            { label: '回退目标', name: 'rebackName', width: 75,align:'center', sortable: false},
            { label: '回退时间', name: 'rebackDate', width: 75,align:'center', sortable: false}

        ],
		viewrecords: true,
        height: 375,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect:true,
        multiboxonly:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

    bindType();

});


var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            sn:null,
            merchantName:null,
            reportName:null,
            terminalType:0,
            rebackName:null
        },
        terminalTypes:[],
        showList: true,
        title:null,


    },
    methods: {
        query: function () {
            vm.reload();
        },
        clean: function () {
            vm.showList = true;
            vm.q = {
                sn:null,
                merchantName:null,
                reportName:null,
                terminalType:0,
                rebackName:null
            };

            $("#jqGrid").jqGrid('setGridParam', {page: 1});
            vm.reload();
        },
        reload: function () {
            vm.showList = true;
            vm.showUpdate=false;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'reportName': vm.q.reportName,
                    'terminalType': vm.q.terminalType,
                    'sn': vm.q.sn,
                    'merchantName':vm.q.merchantName,
                    "rebackName": vm.q.rebackName
                },
                page: page
            }).trigger("reloadGrid");
            bindType();
        }
    }
});



Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

function bindType() {

        $.getJSON(baseURL + "sys/terminalType/list", function (r) {
            vm.$set(vm.terminalTypes, 0, {
                terminalType: 0,
                terminalName: "请选择类型"
            });
            for (var i = 0; i < r.page.length; i++) {
                vm.$set(vm.terminalTypes, (i + 1), r.page[i]);
            }

        })


}